package com.wyg.epkafkastarter.producer;


import com.wyg.epkafkastarter.constant.Topic;
import com.wyg.epkafkastarter.encoder.MailEncoder;
import com.wyg.epkafkastarter.msg.MailMsg;
import org.springframework.kafka.support.SendResult;
import org.springframework.util.concurrent.FailureCallback;
import org.springframework.util.concurrent.SuccessCallback;

/**
 * @Author: WangYongGan
 * @Date: 2022/5/17 16:31
 * @Description:
 */

public class MailProducer {



    private MailProducer() {
    }

    private static final class MailerHolder {
        static final MailProducer MAIL_PRODUCER = new MailProducer();
    }

    public static MailProducer getInstance() {
        return MailerHolder.MAIL_PRODUCER;
    }

    public void send(MailMsg msg){
        final String encode = MailEncoder.encode(msg);
        send(encode);
    }
    public void send(String msg) {
        BaseProducer.send(Topic.EpMail, msg);
    }

    public void send(Topic topic, String msg, SuccessCallback<? super SendResult<String, String>> success, FailureCallback error) {
        BaseProducer.send(Topic.EpMail, msg, success, error);
    }

}
